<template>
  <div class="todo-item">
    <input
      type="checkbox"
      :checked="completed"
      @change="toggleCompletion"
    />
    <span :class="{ completed: completed }">{{ title }}</span>
    <button @click="removeTodo">删除</button>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      required: true,
    },
    completed: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    toggleCompletion() {
      this.$emit('update:completed', !this.completed);
    },
    removeTodo() {
      this.$emit('remove-todo');
    },
  },
};
</script>

<!-- 删除:
<style scoped>
.todo-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.completed {
  text-decoration: line-through;
  color: gray;
}
button {
  margin-left: 10px;
  background-color: red;
  color: white;
  border: none;
  padding: 5px 10px;
  cursor: pointer;
}
</style>
-->

